﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace BLL.Business
{
    public class CommentBLL
    {
        DAL.DataOperate.CommentDAL commDAL = new DAL.DataOperate.CommentDAL();
        public DataSet SelectAll()
        {
           return commDAL.SelectAll();
        }
        public DataSet SelectByCommentId(int CommentId)
        {
            if (CommentId.ToString() == "")
            {
                return null;
            }
            else
            {
                return commDAL.SelectByCommentId(CommentId);
            }
        }
        public DataSet SelectByBookId(int BookId)
        {
            if (BookId.ToString() == "")
                return null;
            else
                return commDAL.SelectByBookId(BookId);
        }

        public bool Insert(Model.Comment comment)
        {
            if (comment.Book_Idint.ToString() == "" ||
                comment.Comm_Captionstr == "" ||
                comment.Comm_Detailtext == "" ||
                comment.Comm_PublishDatedate.ToShortDateString() == "" ||
                comment.Comm_Rankint.ToString() == "" ||
                comment.User_Idint.ToString() == "")
            {
                return false;
            }
            else
            {
                DataSet ds = new DataSet();
                ds = commDAL.SelectByBookUserId(comment.Book_Idint, comment.User_Idint);
                if ((ds == null) ||
                   (ds.Tables.Count == 0) ||
                   (ds.Tables.Count == 1 && ds.Tables[0].Rows.Count == 0))
                {
                    return commDAL.Insert(comment);
                }
                else
                {
                    return false;
                }
            }
        }
        public bool Delete(int CommentId)
        {
            if (CommentId.ToString() == "")
            {
                return false ;
            }
            else
            {
                return commDAL.Delete(CommentId);
            }
        }
    }
}
